| Conditions | 1 |
| Paths | 1 |
| Total Lines | 90 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 19 | function(state, format, visibility, upgrade, data, util) { |
||
| 20 | let ct = this; |
||
| 21 | ct.state = state; |
||
| 22 | ct.data = data; |
||
| 23 | ct.util = util; |
||
| 24 | ct.format = format; |
||
| 25 | ct.cache = { |
||
| 26 | breakdown: {} |
||
| 27 | }; |
||
| 28 | |||
| 29 | ct.update = function(player) { |
||
| 30 | refresh(player); |
||
| 31 | }; |
||
| 32 | |||
| 33 | /* Refreshes the values in the cache */ |
||
| 34 | function refresh(player) { |
||
| 35 | ct.cache.breakdown = {}; |
||
| 36 | for (let element in data.elements) { |
||
| 37 | let exotic = data.elements[element].exotic; |
||
| 38 | if (!player.resources[exotic].unlocked || !player.statistics.dark_run[exotic]) { |
||
| 39 | continue; |
||
| 40 | } |
||
| 41 | let number = player.statistics.dark_run[exotic]; |
||
| 42 | let darkProduction = util.prestigeProduction(number, data.constants.DARK_START, data.constants.DARK_STEP); |
||
| 43 | ct.cache.breakdown[exotic] = Math.round(Math.max(0, darkProduction)); |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | ct.darkProduction = function() { |
||
| 48 | let production = 0; |
||
| 49 | for (let resource in ct.cache.breakdown) { |
||
| 50 | production += ct.cache.breakdown[resource]; |
||
| 51 | } |
||
| 52 | |||
| 53 | return production; |
||
| 54 | }; |
||
| 55 | |||
| 56 | ct.darkPrestige = function(player) { |
||
| 57 | let production = ct.darkProduction(); |
||
| 58 | |||
| 59 | util.addResource(player, 'all_time', 'dark_matter', production, state); |
||
| 60 | |||
| 61 | for (let key in data.elements) { |
||
| 62 | let element = data.elements[key]; |
||
| 63 | player.resources[element.exotic].number = 0; |
||
| 64 | if (!player.exotic_upgrades[key]) { |
||
| 65 | continue; |
||
| 66 | } |
||
| 67 | for (let up in data.exotic_upgrades) { |
||
| 68 | player.exotic_upgrades[key][up] = false; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | for (let slot of player.element_slots) { |
||
| 72 | if (!slot) { |
||
| 73 | continue; |
||
| 74 | } |
||
| 75 | upgrade.resetElement(player, slot.element); |
||
| 76 | } |
||
| 77 | |||
| 78 | for (let i in player.element_slots) { |
||
| 79 | player.element_slots[i] = null; |
||
| 80 | } |
||
| 81 | player.statistics.exotic_run = {}; |
||
| 82 | player.statistics.dark_run = {}; |
||
| 83 | }; |
||
| 84 | |||
| 85 | ct.buyDarkUpgrade = function(name, player) { |
||
| 86 | let upgrades = player.dark_upgrades; |
||
| 87 | let price = data.dark_upgrades[name].price; |
||
| 88 | let currency = 'dark_matter'; |
||
| 89 | upgrade.buyUpgrade(player, |
||
| 90 | upgrades, |
||
| 91 | data.dark_upgrades[name], |
||
| 92 | name, |
||
| 93 | price, |
||
| 94 | currency); |
||
| 95 | }; |
||
| 96 | |||
| 97 | ct.visibleDarkUpgrades = function(player) { |
||
| 98 | return visibility.visible(data.dark_upgrades, isDarkUpgradeVisible, 0, null, player); |
||
| 99 | }; |
||
| 100 | |||
| 101 | // here we receive not the name of the element, but the index in the element_slots |
||
| 102 | function isDarkUpgradeVisible(name, index, player) { |
||
| 103 | return visibility.isUpgradeVisible(name, index, data.dark_upgrades[name], player); |
||
| 104 | } |
||
| 105 | |||
| 106 | state.registerUpdate('dark', ct.update); |
||
| 107 | refresh(state.player); |
||
| 108 | } |
||
| 109 | ]); |
||
| 110 |